/*
 * SafeNativeMethods.cs
 *
 * Contains Safe P/Invoke Methods.
 *
 * Copyright (c) 2005, dnAnalytics. All rights reserved.
 */

#region Using Directives
using System.Runtime.InteropServices;
using System.Security;
using dnAnalytics.Math;
#endregion


namespace dnAnalytics.LinearAlgebra.Native.AtlasClapack
{
    [SuppressUnmanagedCodeSecurity]
    internal static class SafeNativeMethods
    {
        private const string dllName = "atlas.dll";

        #region PInvoke calls

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern double cblas_ddot(int n,  double[] x, int incX,  double[] y, int incY);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void cblas_zdotu_sub(int n,  Complex[] x, int incX,  Complex[] y, int incY, ref Complex dotu);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void cblas_zdotc_sub(int n,  Complex[] x, int incX,  Complex[] y, int incY, ref Complex dotc);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern double cblas_dnrm2(int n,  double[] x, int incX);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern double cblas_dasum(int n,  double[] x, int incX);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern double cblas_dznrm2(int n,  Complex[] x, int incX);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern double cblas_dzasum(int n,  Complex[] x, int incX);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern int cblas_idamax(int n,  double[] x, int incX);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern int cblas_izamax(int n,  Complex[] x, int incX);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void cblas_dswap(int n, [Out] double[] x, int incX, [Out] double[] y, int incY);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void cblas_dcopy(int n,  double[] x, int incX, [Out] double[] y, int incY);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void cblas_daxpy(int n, double alpha,  double[] x, int incX, [Out] double[] y, int incY);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void cblas_drotg(ref double a, ref double b, out double c, out double s);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void cblas_zswap(int n, [Out] Complex[] x, int incX, [Out] Complex[] y, int incY);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void cblas_zcopy(int n,  Complex[] x, int incX, [Out] Complex[] y, int incY);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void cblas_zaxpy(int n, ref Complex alpha,  Complex[] x, int incX, [Out] Complex[] y, int incY);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void cblas_zrotg(ref Complex a, ref Complex b, out Complex c, out Complex s);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void cblas_drotmg(ref double d1, ref double d2, ref double x1, double y1, [Out] double[] p);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void cblas_drot(int n, [Out] double[] x, int incX, [Out] double[] y, int incY, double c, double s);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void cblas_drotm(int n, [Out] double[] x, int incX, [Out] double[] y, int incY, [Out] double[] p);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void cblas_zdrot(int n, [Out] Complex[] x, int incX, [Out] Complex[] y, int incY, double c, double s);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void cblas_dscal(int n, double alpha, [Out] double[] x, int incX);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void cblas_zscal(int n, ref Complex alpha, [Out] Complex[] x, int incX);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void cblas_zdscal(int n, double alpha, [Out] Complex[] x, int incX);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void cblas_dgemv(BlasOrderType order, BlasTransType transA, int m, int n, double alpha,  double[] a, int lda,  double[] x, int incX, double beta, [Out] double[] y, int incY);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void cblas_dgbmv(BlasOrderType order, BlasTransType transA, int m, int n, int kl, int ku, double alpha,  double[] a, int lda,  double[] x, int incX, double beta, [Out] double[] y, int incY);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void cblas_dtrmv(BlasOrderType order, BlasUpLoType uplo, BlasTransType transA, BlasDiagType diag, int n,  double[] a, int lda, [Out] double[] x, int incX);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void cblas_dtbmv(BlasOrderType order, BlasUpLoType uplo, BlasTransType transA, BlasDiagType diag, int n, int k,  double[] a, int lda, [Out] double[] x, int incX);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void cblas_dtpmv(BlasOrderType order, BlasUpLoType uplo, BlasTransType transA, BlasDiagType diag, int n,  double[] ap, [Out] double[] x, int incX);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void cblas_dtrsv(BlasOrderType order, BlasUpLoType uplo, BlasTransType transA, BlasDiagType diag, int n,  double[] a, int lda, [Out] double[] x, int incX);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void cblas_dtbsv(BlasOrderType order, BlasUpLoType uplo, BlasTransType transA, BlasDiagType diag, int n, int k,  double[] a, int lda, [Out] double[] x, int incX);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void cblas_dtpsv(BlasOrderType order, BlasUpLoType uplo, BlasTransType transA, BlasDiagType diag, int n,  double[] ap, [Out] double[] x, int incX);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void cblas_zgemv(BlasOrderType order, BlasTransType transA, int m, int n, ref Complex alpha,  Complex[] a, int lda,  Complex[] x, int incX, ref Complex beta, [Out] Complex[] y, int incY);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void cblas_zgbmv(BlasOrderType order, BlasTransType transA, int m, int n, int kl, int ku, ref Complex alpha,  Complex[] a, int lda,  Complex[] x, int incX, ref Complex beta, [Out] Complex[] y, int incY);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void cblas_ztrmv(BlasOrderType order, BlasUpLoType uplo, BlasTransType transA, BlasDiagType diag, int n,  Complex[] a, int lda, [Out] Complex[] x, int incX);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void cblas_ztbmv(BlasOrderType order, BlasUpLoType uplo, BlasTransType transA, BlasDiagType diag, int n, int k,  Complex[] a, int lda, [Out] Complex[] x, int incX);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void cblas_ztpmv(BlasOrderType order, BlasUpLoType uplo, BlasTransType transA, BlasDiagType diag, int n,  Complex[] ap, [Out] Complex[] x, int incX);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void cblas_ztrsv(BlasOrderType order, BlasUpLoType uplo, BlasTransType transA, BlasDiagType diag, int n,  Complex[] a, int lda, [Out] Complex[] x, int incX);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void cblas_ztbsv(BlasOrderType order, BlasUpLoType uplo, BlasTransType transA, BlasDiagType diag, int n, int k,  Complex[] a, int lda, [Out] Complex[] x, int incX);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void cblas_ztpsv(BlasOrderType order, BlasUpLoType uplo, BlasTransType transA, BlasDiagType diag, int n,  Complex[] ap, [Out] Complex[] x, int incX);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void cblas_dsymv(BlasOrderType order, BlasUpLoType uplo, int n, double alpha,  double[] a, int lda, double[] x, int incX, double beta, [Out] double[] y, int incY);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void cblas_dsbmv(BlasOrderType order, BlasUpLoType uplo, int n, int k, double alpha,  double[] a, int lda,  double[] x, int incX, double beta, [Out] double[] y, int incY);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void cblas_dspmv(BlasOrderType order, BlasUpLoType uplo, int n, double alpha,  double[] ap,  double[] x, int incX, double beta, [Out] double[] y, int incY);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void cblas_dger(BlasOrderType order, int m, int n, double alpha,  double[] x, int incX,  double[] y, int incY, [Out] double[] a, int lda);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void cblas_dsyr(BlasOrderType order, BlasUpLoType uplo, int n, double alpha,  double[] x, int incX, [Out] double[] a, int lda);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void cblas_dspr(BlasOrderType order, BlasUpLoType uplo, int n, double alpha,  double[] x, int incX, [Out] double[] ap);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void cblas_dsyr2(BlasOrderType order, BlasUpLoType uplo, int n, double alpha,  double[] x, int incX,  double[] y, int incY, [Out] double[] a, int lda);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void cblas_dspr2(BlasOrderType order, BlasUpLoType uplo, int n, double alpha,  double[] x, int incX,  double[] y, int incY, [Out] double[] a);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void cblas_zhemv(BlasOrderType order, BlasUpLoType uplo, int n, ref Complex alpha,  Complex[] a, int lda,  Complex[] x, int incX, ref Complex beta, [Out] Complex[] y, int incY);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void cblas_zhbmv(BlasOrderType order, BlasUpLoType uplo, int n, int k, ref Complex alpha,  Complex[] a, int lda,  Complex[] x, int incX, ref Complex beta, [Out] Complex[] y, int incY);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void cblas_zhpmv(BlasOrderType order, BlasUpLoType uplo, int n, ref Complex alpha,  Complex[] ap,  Complex[] x, int incX, ref Complex beta, [Out] Complex[] y, int incY);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void cblas_zgeru(BlasOrderType order, int m, int n, ref Complex alpha,  Complex[] x, int incX,  Complex[] y, int incY, [Out] Complex[] a, int lda);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void cblas_zgerc(BlasOrderType order, int m, int n, ref Complex alpha,  Complex[] x, int incX,  Complex[] y, int incY, [Out] Complex[] a, int lda);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void cblas_zher(BlasOrderType order, BlasUpLoType uplo, int n, double alpha,  Complex[] x, int incX, [Out] Complex[] a, int lda);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void cblas_zhpr(BlasOrderType order, BlasUpLoType uplo, int n, double alpha,  Complex[] x, int incX, [Out] Complex[] a);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void cblas_zher2(BlasOrderType order, BlasUpLoType uplo, int n, ref Complex alpha,  Complex[] x, int incX,  Complex[] y, int incY, [Out] Complex[] a, int lda);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void cblas_zhpr2(BlasOrderType order, BlasUpLoType uplo, int n, ref Complex alpha,  Complex[] x, int incX,  Complex[] y, int incY, [Out] Complex[] ap);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void cblas_dgemm(BlasOrderType order, BlasTransType transA, BlasTransType transB, int m, int n, int k, double alpha,  double[] a, int lda,  double[] b, int ldb, double beta, [Out] double[] c, int ldc);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void cblas_dsymm(BlasOrderType order, BlasSideType side, BlasUpLoType uplo, int m, int n, double alpha,  double[] a, int lda,  double[] b, int ldb, double beta, [Out] double[] c, int ldc);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void cblas_dsyrk(BlasOrderType order, BlasUpLoType uplo, BlasTransType trans, int n, int k, double alpha,  double[] a, int lda, double beta, [Out] double[] c, int ldc);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void cblas_dsyr2k(BlasOrderType order, BlasUpLoType uplo, BlasTransType trans, int n, int k, double alpha,  double[] a, int lda,  double[] b, int ldb, double beta, [Out] double[] c, int ldc);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void cblas_dtrmm(BlasOrderType order, BlasSideType side, BlasUpLoType uplo, BlasTransType transA, BlasDiagType diag, int m, int n, double alpha,  double[] a, int lda, [Out] double[] b, int ldb);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void cblas_dtrsm(BlasOrderType order, BlasSideType side, BlasUpLoType uplo, BlasTransType transA, BlasDiagType diag, int m, int n, double alpha,  double[] a, int lda, [Out] double[] b, int ldb);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void cblas_zgemm(BlasOrderType order, BlasTransType transA, BlasTransType transB, int m, int n, int k, ref Complex alpha,  Complex[] a, int lda, Complex[] b, int ldb, ref Complex beta, [Out] Complex[] c, int ldc);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void cblas_zsymm(BlasOrderType order, BlasSideType side, BlasUpLoType uplo, int m, int n, ref Complex alpha,  Complex[] a, int lda,  Complex[] b, int ldb, ref Complex beta, [Out] Complex[] c, int ldc);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void cblas_zsyrk(BlasOrderType order, BlasUpLoType uplo, BlasTransType trans, int n, int k, ref Complex alpha,  Complex[] a, int lda, ref Complex beta, [Out] Complex[] c, int ldc);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void cblas_zsyr2k(BlasOrderType order, BlasUpLoType uplo, BlasTransType trans, int n, int k, ref Complex alpha,  Complex[] a, int lda,  Complex[] b, int ldb, ref Complex beta, [Out] Complex[] c, int ldc);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void cblas_ztrmm(BlasOrderType order, BlasSideType side, BlasUpLoType uplo, BlasTransType transA, BlasDiagType diag, int m, int n, ref Complex alpha,  Complex[] a, int lda, [Out] Complex[] b, int ldb);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void cblas_ztrsm(BlasOrderType order, BlasSideType side, BlasUpLoType uplo, BlasTransType transA, BlasDiagType diag, int m, int n, ref Complex alpha,  Complex[] a, int lda, [Out] Complex[] b, int ldb);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void cblas_zhemm(BlasOrderType order, BlasSideType side, BlasUpLoType uplo, int m, int n, ref Complex alpha,  Complex[] a, int lda,  Complex[] b, int ldb, ref Complex beta, [Out] Complex[] c, int ldc);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void cblas_zherk(BlasOrderType order, BlasUpLoType uplo, BlasTransType trans, int n, int k, double alpha,  Complex[] a, int lda, double beta, [Out] Complex[] c, int ldc);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void cblas_zher2k(BlasOrderType order, BlasUpLoType uplo, BlasTransType trans, int n, int k, ref Complex alpha,  Complex[] a, int lda,  Complex[] b, int ldb, double beta, [Out] Complex[] c, int ldc);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern int clapack_dgetrf(BlasOrderType order, int m, int n, [Out] double[] a, int lda, [Out] int[] ipiv);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern int clapack_dgetri(BlasOrderType order, int n, [Out] double[] a, int lda,  int[] ipiv, [Out] double[] work, int lwork);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern int clapack_dgetrs(BlasOrderType order, BlasTransType trans, int n, int nrhs,  double[] a, int lda,  int[] ipiv, [Out] double[] b, int ldb);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern int clapack_dpotrf(BlasOrderType order, BlasUpLoType uplo, int n, [Out] double[] a, int lda);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern int clapack_dpotri(BlasOrderType order, BlasUpLoType uplo, int n, [Out] double[] a, int lda);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern int clapack_dpotrs(BlasOrderType order, BlasUpLoType uplo, int n, int nrhs, [Out] double[] a, int lda, [Out] double[] b, int ldb);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern int clapack_zgetrf(BlasOrderType order, int m, int n, [Out] Complex[] a, int lda, [Out] int[] ipiv);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern int clapack_zgetri(BlasOrderType order, int n, [Out] Complex[] a, int lda,  int[] ipiv, [Out] Complex[] work, int lwork);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern int clapack_zgetrs(BlasOrderType order, BlasTransType trans, int n, int nrhs,  Complex[] a, int lda,  int[] ipiv, [Out] Complex[] b, int ldb);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern int clapack_zpotrf(BlasOrderType order, BlasUpLoType uplo, int n, [Out] Complex[] a, int lda);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern int clapack_zpotri(BlasOrderType order, BlasUpLoType uplo, int n, [Out] Complex[] a, int lda);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern int clapack_zpotrs(BlasOrderType order, BlasUpLoType uplo, int n, int nrhs, [Out] Complex[] a, int lda, [Out] Complex[] b, int ldb);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern int dgeqp3_(ref int m, ref int n, [Out] double[] a, ref int lda, [Out] int[] jpvt, [Out] double[] tau, [Out] double[] work, ref int lwork, ref int info);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern int dgesvd_(ref char jobu, ref char jobvt, ref int m, ref int n,  [Out] double[] a, ref int lda, [Out] double[] s, [Out] double[] u, ref int ldu, [Out] double[] vt, ref int ldvt, [Out] double[] work, ref int lwork, ref int info);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern int dorgqr_(ref int m, ref int n, ref int k, [Out] double[] a, ref int lda,  double[] tau, [Out] double[] work, ref int lwork, ref int info);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern int dormqr_(ref char side, ref char trans, ref int m, ref int n, ref int k,  double[] a, ref int lda,  double[] tau, [Out] double[] c, ref int ldc, [Out] double[] work, ref int lwork, ref int info);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern int zgeqp3_(ref int m, ref int n, [Out] Complex[] a, ref int lda, [Out] int[] jpvt, [Out] Complex[] tau, [Out] Complex[] work, ref int lwork, [Out] double[] rwork, ref int info);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern int zungqr_(ref int m, ref int n, ref int k, [Out] Complex[] a, ref int lda,  Complex[] tau, [Out] Complex[] work, ref int lwork, ref int info);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern int zunmqr_(ref char side, ref char trans, ref int m, ref int n, ref int k,  Complex[] a, ref int lda,  Complex[] tau, [Out] Complex[] c, ref int ldc, [Out] Complex[] work, ref int lwork, ref int info);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern int zgesvd_(ref char jobu, ref char jobvt, ref int m, ref int n, [Out] Complex[] a, ref int lda, [Out] double[] s, [Out] Complex[] u, ref int ldu, [Out] Complex[] v, ref int ldvt, [Out] Complex[] work, ref int lwork, [Out] double[] rwork, ref int info);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern int dgels_(ref char trans, ref int m, ref int n, ref int nrhs, [Out] double[] a, ref int lda, double[] b, ref int ldb, [Out] double[] work, ref int lwork, ref int info);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern int zgels_(ref char trans, ref int m, ref int n, ref int nrhs, [Out] Complex[] a, ref int lda, [Out] Complex[] b, ref int ldb, [Out] Complex[] work, ref int lwork, ref int info);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern int dgelss_(ref int m, ref int n, ref int nrhs, [Out] double[] a, ref int lda, [Out] double[] b, ref int ldb, [Out] double[] s, ref double rcond, ref int rank, [Out] double[] work, ref int lwork, ref int info);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern int zgelss_(ref int m, ref int n, ref int nrhs, [Out] Complex[] a, ref int lda, [Out] Complex[] b, ref int ldb, [Out] double[] s, ref double rcond, ref int rank, [Out] Complex[] work, ref int lwork, [Out] double[] rwork, ref int info);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern int dgelsy_(ref int m, ref int n, ref int nrhs, [Out] double[] a, ref int lda, [Out] double[] b, ref int ldb, [Out] int[] jpvt, ref double rcond, ref int rank, [Out] double[] work, ref int lwork, ref int info);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern int zgelsy_(ref int m, ref int n, ref int nrhs, [Out] Complex[] a, ref int lda, [Out] Complex[] b, ref int ldb, [Out] int[] jpvt, ref double rcond, ref int rank, [Out] Complex[] work, ref int lwork, [Out] double[] rwork, ref int info);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern double dlange_(ref char norm, ref int m, ref int n,  double[] a, ref int lda,  double[] work);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern double zlange_(ref char norm, ref int m, ref int n,  Complex[] a, ref int lda,  double[] work);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern int dgecon_(ref char norm, ref int n,  double[] a, ref int lda, ref double anorm, ref double rcond,  double[] work,  int[] iwork, ref int info);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern int zgecon_(ref char norm, ref int n,  Complex[] a, ref int lda, ref double anorm, ref double rcond,  Complex[] work,  double[] rwork, ref int info);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern int ilaenv_(ref int ispec, string name, string opts, ref int n1, ref int n2, ref int n3, ref int n4, long name_len, long opts_len);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern int dgeqrf_(ref int m, ref int n, [Out] double[] a, ref int lda, [Out] double[] tau, [Out] double[] work, ref int lwork, ref int info);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern int zgeqrf_(ref int m, ref int n, [Out] Complex[] a, ref int lda, [Out] Complex[] tau, [Out] Complex[] work, ref int lwork, ref int info);

        #endregion PInvoke calls
    }
}